package net.hmapp.app.activity;

import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;

//import net.hmapp.app.R;

public class MainActivity2 extends AppCompatActivity {

    private EditText etUsername;
    private EditText etPassword;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main2);

        // 绑定控件
        etUsername = findViewById(R.id.et_username);
        etPassword = findViewById(R.id.et_password);
        Button btnLogin = findViewById(R.id.btn_login);

        // 设置登录按钮点击事件
        btnLogin.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                // 获取输入内容
                String username = etUsername.getText().toString().trim();
                String password = etPassword.getText().toString().trim();

                // 简单校验（实际开发中可替换为接口校验）
                if (TextUtils.isEmpty(username)) {
                    Toast.makeText(MainActivity2.this, "请输入用户名", Toast.LENGTH_SHORT).show();
                    return;
                }

                if (TextUtils.isEmpty(password)) {
                    Toast.makeText(MainActivity2.this, "请输入密码", Toast.LENGTH_SHORT).show();
                    return;
                }

                // 模拟登录验证（正确账号：user123，密码：user123）
                if ("user123".equals(username) && "user123".equals(password)) {
                    Toast.makeText(MainActivity2.this, "登录成功", Toast.LENGTH_SHORT).show();

                    // 登录成功后跳转到MainActivity
                    Intent intent = new Intent(MainActivity2.this, MainActivity.class);
                    startActivity(intent);

                    // 关闭当前登录页面，防止返回
                    finish();
                } else {
                    Toast.makeText(MainActivity2.this, "账号或密码错误", Toast.LENGTH_SHORT).show();
                }
            }
        });
    }
}